﻿@model AspSQLProvider.PgMembershipUser

@{
    var X = Html.X();
}

@(
 X.GridPanel()
        .Title("Lista de usuarios")
        .Flex(1)
        .Store(
            X.StoreForModel()
                .ID("storeUsuarios")
                .Proxy(X.AjaxProxy()
                    .Url(Url.Action("GetListUsuarios"))
                    .Reader(X.JsonReader().RootProperty("data"))
                )
                .RemoteSort(false)
                .PageSize(20)
        )
        .DirectEvents(de => { 
            de.ItemDblClick.Url = Url.Action("RunCommandGrid", "Usuarios");
            de.ItemDblClick.ExtraParams.Add(new Parameter { Name = "commandName", Value = "cmdEditar", Mode = ParameterMode.Value });
            de.ItemDblClick.ExtraParams.Add(new Parameter { Name = "userName", Value = "record.data.UserName", Mode = ParameterMode.Raw });
            de.ItemDblClick.Before = "Ext.getBody().mask('Cargando...!', 'x-mask-loading');";
            de.ItemDblClick.Complete = "Ext.getBody().unmask();";
            de.ItemDblClick.Failure = "PcaGlobal.showError(result.msg);";
        })
        .ColumnModel(
            X.Column().DataIndex(Model, m => m.UserName).Text("Usuario").Flex(1),
            X.Column().DataIndex(Model, m => m.nick).Text("Nick").Flex(1),
            X.Column().DataIndex(Model, m => m.Email).Text("Email").Flex(1),
            X.Column().DataIndex(Model, m => m.zonaHoraria).Text("Zona Horaria").Flex(1),
            X.CheckColumn().DataIndex(Model, m => m.IsApproved).Text("Activo?"),
            X.CheckColumn().DataIndex(Model, m => m.IsLockedOut).Text("Bloqueado?"),
            X.CommandColumn().Hideable(false).Text("Operaciones").Align(Alignment.Center).Width(112)
                .Commands(
                    X.GridCommand().CommandName("cmdEditar").ToolTip(t => t.Text = "Editar usuario").Icon(Icon.UserEdit),
                    X.GridCommand().CommandName("cmdCambiarPassword").ToolTip(t => t.Text = "Cambiar password").Icon(Icon.UserKey),
                    X.GridCommand().Icon(Icon.ArrowDown).Menu(men => {
                       men.Items.Add(X.MenuCommand().CommandName("cmdEliminar").Text("Eliminar usuario").Icon(Icon.UserDelete));
                       men.Items.Add(X.MenuCommand().CommandName("cmdEditarRoles").Text("Editar roles").Icon(Icon.UserGo));
                       men.Items.Add(X.MenuCommand().CommandName("cmdAsignarOficina").Text("Asignar oficina").Icon(Icon.ApplicationHome)); 
                    })
                )
                .DirectEvents(de =>
                {
                    de.Command.Url = Url.Action("RunCommandGrid", "Usuarios");
                    de.Command.ExtraParams.Add(new Parameter { Name = "commandName", Value = "command", Mode = ParameterMode.Raw });
                    de.Command.ExtraParams.Add(new Parameter { Name = "userName", Value = "record.data.UserName", Mode = ParameterMode.Raw });
                    de.Command.Before = "Ext.getBody().mask('Cargando...!', 'x-mask-loading');";
                    de.Command.Complete = "Ext.getBody().unmask();";
                    de.Command.Failure = "PcaGlobal.showError(result.msg);";
                })
       )
       .TopBar(
            X.Toolbar()
                .Items(
                    X.Button()
                        .Text("Nuevo usuario")
                        .Icon(Icon.Add)
                        .DirectEvents(de =>
                        {
                            de.Click.Url = Url.Action("FrmRegistrar", "Usuarios");
                            de.Click.Before = "Ext.getBody().mask('Cargando...!', 'x-mask-loading');";
                            de.Click.Complete = "Ext.getBody().unmask();";
                        })
                )
       )
       .BottomBar(
            X.PagingToolbar()
                .DisplayInfo(true)
                .DisplayMsg("Mostrando usuarios {0}-{1} de {2}")
                .EmptyMsg("No existen usuarios")
       )
)
